<?php

function smarty_function_wysiwyg($params, &$smarty)
{
	
	if(!isset($params["id"])) $params["id"]="input";
	if(!isset($params["height"])) $params["height"]=600;
	if(!isset($params["width"])) $params["width"]=800;
	if(!isset($params["minHeight"])) $params["minHeight"]=800;
	if(!isset($params["maxHeight"])) $params["maxHeight"]=1200;
	if(!isset($params["minWidth"])) $params["minWidth"]=600;
	if(!isset($params["maxWidth"])) $params["maxWidth"]=800;
	if(!isset($params["value"])) $params["value"]= "";
	
	$input = '<textarea cols="100" id="'.$params["id"].'" name="'.$params["id"].'" rows="10">'.$params["value"].'</textarea>';
	
	$jscript = '<script type="text/javascript">
					var editor = CKEDITOR.replace( "'.$params["id"].'" );
						editor.config.height = "'.$params["height"].'";
						editor.config.resize_minHeight = "'.$params["minHeight"].'";
						editor.config.resize_maxHeight = "'.$params["maxHeight"].'";
						
						editor.config.width = "'.$params["width"].'";
						editor.config.resize_minWidth = "'.$params["minWidth"].'";
						editor.config.resize_maxWidth = "'.$params["maxWidth"].'";
						
						editor.config.autoParagraph = false;
						editor.config.enterMode = CKEDITOR.ENTER_BR;
						editor.config.fullPage = true;
						editor.config.startupMode = "source";
	</script>
	<script type="text/javascript">
			CKEDITOR.instances.'.$params["id"].'.on("instanceReady", function () {

				//set keyup event
				$(document).on("keyup", function () { CKEDITOR.instances.'.$params["id"].'.updateElement(); });
				//and paste event
				$(document).on("paste", function () { CKEDITOR.instances.'.$params["id"].'.updateElement(); });

			});	
	</script>';
	
	return $input.$jscript;
}


	
	